package cn.rkylin.oms.refund.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.ectrade.vo.EcTradeVO;
import cn.rkylin.oms.refund.vo.RefundVO;

/**
 * 平台退款单数据访问层
 * 
 * @author jipengcheng
 * @created 2017.04.12
 *
 */
@Repository(value = "ecRefundItemDAO")
public class IRefundDaoImpl implements IRefundDAO {

    @Resource(name = "redisTemplate")
    private RedisTemplate<Serializable, Serializable> redisTemplate;
    
	@Autowired
	protected IDataBaseFactory dao;

	@Override
	public RefundVO findById(String ecRefundId) throws Exception {
		List<RefundVO> resultList = dao.findList("selectByPrimaryKeyRefund", ecRefundId);
		if (resultList != null && resultList.size() > 0) {
			return resultList.get(0);
		}
		return null;
	}
	
	/**
	 * 退款单检索
	 */
	public List<RefundVO> findRefundList(String pageStatement, Map reqMap) throws Exception {
	    List<RefundVO> list = dao.findList(pageStatement, reqMap);
        return list;
	}

    @Override
    public int update(RefundVO refundVO) throws Exception {
        redisTemplate.delete("淘宝-Refund-EcRefundCode:"+refundVO.getEcRefundCode());
        return dao.update("updateByPrimaryKeySelectiveRefund", refundVO);
    }
}
